package io;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class CopyCharcterFile {
    public static void main(String[] args) throws IOException {
        File srcFile = new File("C:\\Users\\ASUS\\Desktop\\Files\\test.txt");
        File descFile = new File("C:\\Users\\ASUS\\Desktop\\Files\\new.txt");

        FileReader srcfileReader = new FileReader(srcFile);
        FileWriter descfileWriter = new FileWriter(descFile);

        char[] bufs = new char[1024];
        //如果length为-1，表示文件结尾
        int length = srcfileReader.read(bufs);
        while(length != -1){
            descfileWriter.write(bufs,0,length);
            String str = new String(bufs,0,length);
            System.out.println(str);
            length = srcfileReader.read(bufs);
        }
        descfileWriter.flush();
    }
}
